package com.hmilyylimh.cloud.wrapper.cglib;

import org.springframework.cglib.core.DebuggingClassWriter;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.stereotype.Component;

/**
 * <h1><a href="https://time.geekbang.org/column/intro/100312101">极客专栏地址：https://time.geekbang.org/column/intro/100312101</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/GeekDubbo3Tutorial">案例代码地址：https://gitee.com/ylimhhmily/GeekDubbo3Tutorial</a></h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2022-09-04
 */
@Component
public class CglibService {

    public String sayHello(String name) {
        return "Hello: " + name;
    }

    public String pay(String goodName) {
        return "Paid: " + goodName;
    }

    public static void main(String[] args) {
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,
                "/Users/hehui/Hmily/opensource/GeekDubbo3Tutorial/dubbo-15-dubbo-wrapper/target");

        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(CglibService.class);
        enhancer.setCallback(new CglibServiceInterceptor());
        CglibService cglibProxy = (CglibService) enhancer.create();
        System.out.println(cglibProxy.sayHello("Geek"));
    }
}